<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page language="java"
	import="com.crystaldecisions.sdk.exception.SDKException,
            com.crystaldecisions.sdk.framework.CrystalEnterprise,
            com.crystaldecisions.sdk.framework.IEnterpriseSession,
            com.crystaldecisions.sdk.framework.ISessionMgr,
            com.crystaldecisions.sdk.framework.ITrustedPrincipal,
            java.text.SimpleDateFormat,
            java.util.Date,
            java.net.URLEncoder"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>小微项目-分公司周报表</title>
</head>
<body>
	<%!public String getToken(String cms, String username) {
		String enterpriseToken = "";
		String sharedKey = "03efbfbd732befbfbde7898b380607efbfbd11efbfbdefbfbdefbfbdefbfbdefbfbd721c1f78efbfbdefbfbdefbfbdefbfbdefbfbdefbfbdefbfbdefbfbd62efbfbd3befbfbdefbfbd120504d6aaefbfbdefbfbd12efbfbd45efbfbd1a5f42efbfbdda9fefbfbdefbfbdefbfbd37335a32efbfbd55efbfbdefbfbd25";

		try {
			ISessionMgr sessionMgr = CrystalEnterprise.getSessionMgr();

			ITrustedPrincipal trustedPrincipal = sessionMgr
					.createTrustedPrincipal(username, cms, sharedKey);
			IEnterpriseSession enterpriseSession = sessionMgr
					.logon(trustedPrincipal);
			enterpriseToken = enterpriseSession.getLogonTokenMgr()
					.getDefaultToken();
			System.out.println("enterpriseToken:=" + enterpriseToken);
		} catch (SDKException e) {
			// e.printStackTrace();
			System.out.println("Login False!");
			enterpriseToken = "";
		}
		return enterpriseToken;
	}%>
	<%
		String defaultToken = "";
		//分公司-周报表
		String url1 = "http://bo.joeone.net:8080/BOE/OpenDocument/opendoc/openDocument.jsp?sIDType=CUID&iDocID=AQVmhDkWsh9Ct8hqZR5De8E&token=";

		String cms = "192.168.199.239:6400"; //request.getParameter("cms"); 
		String username = "chenhoucheng"; //request.getParameter("username"); 
		String conStr = "";
		if ("".equals(cms) || cms == null)
			cms = "192.168.199.239:6400";
		if ("".equals(username) || username == null)
			username = " ";
		if (!"".equals(username)) {
			defaultToken = getToken(cms, username);
			String werks = request.getParameter("公司代码");
			String year = request.getParameter("年份(分公司)");
			String week = request.getParameter("周数(分公司)");
			String month = request.getParameter("月份(分公司)");
			

			url1 = url1 + defaultToken;
			conStr = "&lsRVAR_YEAR001=[" + year + ".." + year+"]";
			//当前时间
			Date date = new Date();
			//月 改成需要传输
			/* SimpleDateFormat df = new SimpleDateFormat("yyyy");
			String dfStr = df.format(date); */

			conStr += "&lsRVAR_RLNY019=[" + year+"."+month + ".." + year+"."+month+"]";
			//周
			conStr += "&lsRVAR_RLNZ008=[" + year + "." + week + ".." + year + "." + week +"]";
			if(werks.equals("5140") || werks.equals("5141")){
				conStr += "&lsMGSDM=5140;5141";
			}else{
				conStr += "&lsMGSDM=" + werks + ";" + werks;
			}
			conStr += "&lsSVAR_YEAR002=" +String.valueOf(Integer.valueOf(year)-1);
			conStr += "&lsSVAR_RLNY001=" +String.valueOf(Integer.valueOf(year)-1)+month;
			conStr += "&lsSVAR_RLNY014=" +String.valueOf(Integer.valueOf(year))+month;
			
			//url1 += conStr;

			//out.println("url1="+url1);
		}
	%>
	<%
		if (!"".equals(defaultToken)) {
			//out.println("url1=" + url1);
			//out.println("url2=" + url1+URLEncoder.encode(conStr, "GBK"));
			//response.setCharacterEncoding("GBK");
			//response.sendRedirect(URLEncoder.encode(url1, "GBK"));
			response.sendRedirect(url1 += conStr);

		} else {
	%>
	Login False!
	<%
		}
	%>
</body>
</html>
